class Solution {
public:
    string addStrings(string num1, string num2) {
        int end1 = num1.size() - 1;
        int end2 = num2.size() - 1;
        int ret = 0;
        int next = 0;
        string str;
        while(end1 >= 0 || end2 >= 0){
            ret = 0;
            if(end1 >= 0)
                ret += num1[end1--] - '0';
            if(end2 >= 0)
                ret += num2[end2--] - '0';
            ret += next;
            next = 0;
            if(ret > 9){
                next = 1;
                ret -= 10;
            }
            str += (ret + '0');
        }
        if(next == 1)
            str += '1';
        reverse(str.begin(),str.end());
        return str;
    }
}; 